<%@ page import="com.fhd.constant.Constants" %>
<%@ page import="com.fhd.pojo.Merchant" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.fhd.pojo.House" %>
<%@ page import="java.util.Objects" %><%--
  Created by IntelliJ IDEA.
  User: 44252
  Date: 2025/3/31
  Time: 9:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>商户房型管理</title>
</head>
<body>
<h1>商户房型管理</h1>
<a href="<%=request.getContextPath()%>/jsp/merchantFrame.jsp">返回</a>
<br>
<a href="<%=request.getContextPath()%>/jsp/merchantAddHouse.jsp">增加房型</a>
<br><br>
<%
    // 删除房型返回信息
    String object = (String)request.getSession().getAttribute(Constants.ADD_HOUSE_MESSAGE);
    if (!Objects.isNull(object)) {
        out.print("<h4 style=\"color: red\">" + object + "</h4>");
        request.getSession().removeAttribute(Constants.ADD_HOUSE_MESSAGE);
    }
    // 添加房型返回信息
    String object1 = (String)request.getSession().getAttribute(Constants.DELETE_HOUSE_MESSAGE);
    if (!Objects.isNull(object1)) {
        out.print("<h4 style=\"color: red\">" + object1 + "</h4>");
        request.getSession().removeAttribute(Constants.DELETE_HOUSE_MESSAGE);
    }
    // 修改房型返回信息
    String object2 = (String)request.getSession().getAttribute(Constants.UPDATE_HOUSE_MESSAGE);
    if (!Objects.isNull(object2)) {
        out.print("<h4 style=\"color: red\">" + object2 + "</h4>");
        request.getSession().removeAttribute(Constants.UPDATE_HOUSE_MESSAGE);
    }
%>
<%--接受后端来的数据--%>
<%
    String message = (String)request.getSession().getAttribute(Constants.GET_MERCHANT_HOUSE_MESSAGE);
    // 有信息或者有Session
    if (message != null) {
        out.print("<h3 style=\"color: red\">" + message + "</h3>");
        request.getSession().removeAttribute(Constants.GET_MERCHANT_HOUSE_MESSAGE);
    } else {
        ArrayList<House> houses = (ArrayList<House>) request.getSession().getAttribute(Constants.GET_MERCHANT_HOUSE_SESSION);
        for (House house : houses) {
            out.print("房型id：" + house.getId() + "<br>");
            out.print("房型名：" + house.getHouseName() + "<br>");
            out.print("价格：" + house.getPrice() + "<br>");
            out.print("剩余数量：" + house.getRemainNumber() + "<br>");
            out.print("关键词：" + house.getKeyWord() + "<br>");
%>
<a href="<%=request.getContextPath()%>/jsp/merchantUpdateHouse.jsp?id=<%=house.getId()%>">修改房型</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="<%=request.getContextPath()%>/merchant.do?method=deleteHouse&id=<%=house.getId()%>">删除房型</a>
<br>

<%
            out.print("=========================================<br>");
        }
    }

%>
</body>
</html>
